/*
 *	The countio program prints a horizontal histogram of 0 to 9, 
 *	all case letters, white space and other characters.
 *	Copyright (C) 1989-2089 Sergey Sergeevich Tsybanov All Rights Reserved
 *
 *	Countio is free software: you can redistribute it and/or modify 
 *	it under the terms of the GNU General Public License as published 
 *	by the Free Software Foundation, either version 3 of the License, 
 *	or (at your option) any later version.
 *
 *	Countio is distributed in the hope that it will be useful, but 
 *	WITHOUT ANY WARRANTY; without even the implied warranty of 
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 *	See the GNU General Public License for more details.
 *
 *	You should have received a copy of the GNU General Public License 
 *	along with the countio program. 
 *	If not, see <https://www.gnu.org/licenses/>.
 */

#include <stdio.h>

#define ALPHABET_COUNT 26
#define CHAR_COLON ':'
#define CHAR_COMMA ','
#define CHAR_EXCLAIM '!'
#define CHAR_NEWLINE '\n'
#define CHAR_NINE '9'
#define CHAR_PERIOD '.'
#define CHAR_QUESTION '?'
#define CHAR_SEMICOLON ';'
#define CHAR_TAB '\t'
#define CHAR_WHITE ' '
#define CHAR_ZERO '0'
#define DIGITS_COUNT 10
#define LETTERS_COUNT 52
#define LOWER_CASE_LETTER_END 123
#define LOWER_CASE_LETTER_START 97
#define ONE 1
#define UPPER_CASE_LETTER_END 91
#define UPPER_CASE_LETTER_START 65
#define ZERO 0

/*
 *	Print a horizontal histogram of 0 to 9, all case letters,
 *	white space and other characters.
 */
int main( void) {
    char symbol;
    long i, countColon, countComma, countExclaim, countNewline, countPeriod, 
    countQuestion, countSemicolon, countTab, countWhite;    
    long countDigits[ DIGITS_COUNT], countLetters[ LETTERS_COUNT];
 
    /*
     *	Zero out the counters.
     */
    countColon = countComma = countExclaim = countNewline = countPeriod
    = countQuestion = countSemicolon = countTab = countWhite = ZERO;
    for ( i = ZERO; i < DIGITS_COUNT; ++i)
        countDigits[ i] = ZERO;
    for ( i = ZERO; i < LETTERS_COUNT; ++i)
        countLetters[ i] = ZERO;

    /*
     *	Get the count values of inputs.
     */
    while ( ( symbol = getchar()) != EOF)
        if ( symbol >= CHAR_ZERO && symbol <= CHAR_NINE)
            ++countDigits[ symbol - CHAR_ZERO];
        else if ( symbol >= UPPER_CASE_LETTER_START 
                && symbol < UPPER_CASE_LETTER_END)
            ++countLetters[ symbol - UPPER_CASE_LETTER_START];
        else if ( symbol >= LOWER_CASE_LETTER_START
                && symbol < LOWER_CASE_LETTER_END)
            ++countLetters[ symbol - LOWER_CASE_LETTER_START 
                            + ALPHABET_COUNT];                
        else {
            switch ( symbol) {
                case CHAR_COLON:
                    ++countColon;
                    break;
                case CHAR_COMMA:
                    ++countComma;
                    break;
                case CHAR_EXCLAIM:
                    ++countExclaim;
                    break;
                case CHAR_NEWLINE:
                    ++countNewline;
                    break;
                case CHAR_PERIOD:
                    ++countPeriod;
                    break;
                case CHAR_QUESTION:
                    ++countQuestion;
                    break;
                case CHAR_SEMICOLON:
                    ++countSemicolon;
                    break;
                case CHAR_TAB:
                    ++countTab;
                    break;
                case CHAR_WHITE:
                    ++countWhite;
                    break;
            }
        }

    /*
     *	Print the histogram.
     */
    printf( "\n========================================\n");
    printf( "=       The IO counting histogram      =\n");
    printf( "========================================\n");
    for ( i = ZERO; i < DIGITS_COUNT; ++i) {
        long j;
        printf( "= %ld = ", i);
        for ( j = ZERO; j < countDigits[ i]; ++j)
            printf( "X");
        printf( "\n");
    }
    for ( i = ZERO; i < LETTERS_COUNT; ++i) {
        long j;
        printf( "= %c = ", 
                i < ALPHABET_COUNT ? 
                (char) ( i + UPPER_CASE_LETTER_START) :
                (char) ( i + LOWER_CASE_LETTER_START 
                - ALPHABET_COUNT));
        for ( j = ZERO; j < countLetters[ i]; ++j)
            printf( "X");
        printf( "\n");
    }
    printf( "= : = ");
    for ( i = ZERO; i < countColon; ++i)
        printf( "X");
    printf( "\n");
    printf( "= , = ");
    for ( i = ZERO; i < countComma; ++i)
        printf( "X");
    printf( "\n");
    printf( "= ! = ");
    for ( i = ZERO; i < countExclaim; ++i)
        printf( "X");
    printf( "\n");
    printf( "=\\n = ");
    for ( i = ZERO; i < countNewline; ++i)
        printf( "X");
    printf( "\n");
    printf( "= . = ");
    for ( i = ZERO; i < countPeriod; ++i)
        printf( "X");
    printf( "\n");
    printf( "= ? = ");
    for ( i = ZERO; i < countQuestion; ++i)
        printf( "X");
    printf( "\n");
    printf( "= ; = ");
    for ( i = ZERO; i < countSemicolon; ++i)
        printf( "X");
    printf( "\n");
    printf( "=\\t = ");
    for ( i = ZERO; i < countTab; ++i)
        printf( "X");
    printf( "\n");
    printf( "=' '= ");
    for ( i = ZERO; i < countWhite; ++i)
        printf( "X");
    printf( "\n");
    printf( "========================================\n");

    return ZERO;
}